<?php
/**
 * Created by JetBrains PhpStorm.
 * User: CACA-PC
 * Date: 26/12/2013
 * Time: 08:53
 * To change this template use File | Settings | File Templates.
 */
class Model_Banner extends CI_Model{
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    // Lay UserId by Email
    public function getUseridbyEmail($email)
    {
        $url ="http://egov047.juddy.vn/api/user?email=".$email;
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        foreach ($json_data as $khoa=>$value) {
                return $value['UserId'];
                break;
        }
    }

    // Lay UserId by User Name
    public function getUseridbyUserName($username)
    {
        $url ="http://egov047.juddy.vn/api/user/getall";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        foreach ($json_data as $khoa=>$value) {
            if ( $username == $value['UserName'] )
            {
                return $value['UserId'];
                break;
            }
        }
    }

    // Lay Group
    public function getListGroup()
    {
        $url ="http://egov047.juddy.vn/api/Group/GetALL";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        return $json_data;
    }

    // Kiem tra Email có ton tai khong
    public function checkEmailBanner($email_check)
    {
        $url ="http://egov047.juddy.vn/api/User/GetAll";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        foreach ($json_data as $khoa=>$value) {
            if ( $email_check == $value['Email'] )
            {
                return "1";
                break;
            }
        }
        return "0";
    }

    // Kiem tra UserName có ton tai khong
    public function checkUserNamelBanner($username_check)
    {
        $url ="http://egov047.juddy.vn/api/User/GetAll";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        foreach ($json_data as $khoa=>$value) {
            if ( $username_check == $value['UserName'] )
            {
                return "1";
                break;
            }
        }
        return "0";
    }

    // Lay List Email cua cac user
    public function getListEmailBanner()
    {
        $url ="http://egov047.juddy.vn/api/User/GetAll";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        $listEmail = array();
        foreach ($json_data as $khoa=>$value) {
            $listEmail[] = $value['Email'];
        }
        return $listEmail;
    }

    // Lay List UserName cua cac user
    public function getListUserNameBanner()
    {
        $url ="http://egov047.juddy.vn/api/User/GetAll";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        $listEmail = array();
        foreach ($json_data as $khoa=>$value) {
            $listEmail[] = $value['UserName'];
        }
        return $listEmail;
    }

    // lay banner theo ma id
    public function getBanner()
    {
        $url ="http://egov047.juddy.vn/api/Ban/GetAll";
        $json = file_get_contents($url);
        $json_data = json_decode($json,true);
        return $json_data;
    }


}
?>